<template>
  <div class="route-manage-container">
    <!-- 页面头部 -->
    <div class="page-header">
      <h3>路由管理</h3>
    </div>

    <!-- 工具栏 -->
    <div class="toolbar">
      <div class="left-section">
        <h3>路由列表</h3>
        <div class="route-summary">
          <span class="summary-text">
            共 {{ filteredRoutes.length }} 条路由
          </span>
        </div>
      </div>

      <div class="right-section">
        <el-input
          v-model="searchQuery"
          placeholder="搜索路由名称或路由地址..."
          clearable
          class="search-input"
        >
          <template #prefix>
            <SvgIcon name="search" size="16px" />
          </template>
        </el-input>

        <el-button
          type="primary"
          size="default"
          @click="refreshRoutes"
          :loading="loading"
          plain
        >
          <SvgIcon name="reload" size="18px" />
          <span style="margin-left: 6px">刷新</span>
        </el-button>

        <el-button type="primary" size="default" @click="openAddModal">
          <SvgIcon name="add" size="18px" />
          <span style="margin-left: 6px">新增路由</span>
        </el-button>
      </div>
    </div>

    <!-- 路由列表 -->
    <div class="routes-content" v-loading="loading">
      <div v-if="error" class="error-message">
        <el-alert :title="error" type="error" show-icon :closable="false">
          <template #default>
            <el-button @click="refreshRoutes" size="small" type="primary">
              重试
            </el-button>
          </template>
        </el-alert>
      </div>

      <div v-else-if="filteredRoutes.length === 0" class="empty-message">
        <el-empty
          :description="searchQuery ? '没有找到匹配的路由' : '暂无路由数据'"
          :image-size="120"
        />
      </div>

      <div v-else class="route-table">
        <el-table
          :data="paginatedRoutes"
          style="width: 100%"
          stripe
          @row-click="viewRoute"
          :header-cell-style="{ color: '#606266' }"
          height="calc(100vh - 290px)"
          :empty-text="''"
        >
          <el-table-column
            prop="link_name"
            label="路由名称"
            min-width="100"
            align="center"
            show-overflow-tooltip
          >
            <template #default="scope">
              <div class="route-name-cell">
                <span class="route-name">
                  {{ scope.row.link_name || '未命名路由' }}
                </span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="url"
            label="路由地址"
            min-width="260"
            align="center"
            show-overflow-tooltip
          >
            <template #default="scope">
              <div class="route-url-cell">
                <el-tooltip
                  :content="scope.row.url"
                  placement="top"
                  :disabled="!scope.row.url"
                >
                  <span class="route-url">{{ scope.row.url }}</span>
                </el-tooltip>
                <el-tooltip content="复制路由地址" placement="top">
                  <el-button
                    @click.stop="copyToClipboard(scope.row.url)"
                    size="small"
                    type="default"
                    class="copy-btn"
                  >
                    <SvgIcon name="copy" size="14px" />
                  </el-button>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="created_at"
            label="创建时间"
            width="160"
            align="center"
            show-overflow-tooltip
          >
            <template #default="scope">
              <span class="route-time">
                {{ formatDate(scope.row.created_at) }}
              </span>
            </template>
          </el-table-column>

          <el-table-column
            label="操作"
            width="260"
            align="center"
            fixed="right"
          >
            <template #default="scope">
              <div class="action-buttons">
                <el-button
                  @click.stop="viewRoute(scope.row)"
                  size="small"
                  type="primary"
                  plain
                >
                  查看
                </el-button>
                <el-button
                  @click.stop="editRoute(scope.row)"
                  size="small"
                  type="success"
                  plain
                >
                  编辑
                </el-button>
                <el-button
                  @click.stop="confirmDelete(scope.row)"
                  size="small"
                  type="danger"
                  plain
                >
                  删除
                </el-button>
              </div>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页器 -->
        <div class="pagination-container">
          <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[10, 20, 50, 100]"
            :total="filteredRoutes.length"
            background
            layout="total, sizes, prev, pager, next, jumper"
            small
          />
        </div>
      </div>
    </div>

    <!-- 路由弹窗 -->
    <el-dialog
      v-model="showModal"
      :title="modalTitle"
      :width="modalMode === 'view' ? '600px' : '800px'"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      destroy-on-close
    >
      <!-- 查看模式 -->
      <div v-if="modalMode === 'view'" class="view-content">
        <el-descriptions :column="1" border>
          <el-descriptions-item label="路由名称">
            {{ currentRoute.link_name || '未命名路由' }}
          </el-descriptions-item>
          <el-descriptions-item label="路由地址">
            <div class="route-url-display">
              <el-tooltip
                :content="currentRoute.url"
                placement="top"
                :disabled="!currentRoute.url"
              >
                <span class="route-url">{{ currentRoute.url }}</span>
              </el-tooltip>
              <el-tooltip content="复制路由地址" placement="top">
                <el-button
                  @click="copyToClipboard(currentRoute.url)"
                  size="small"
                  type="default"
                  class="copy-btn"
                >
                  <SvgIcon name="copy" size="14px" />
                </el-button>
              </el-tooltip>
            </div>
          </el-descriptions-item>
          <el-descriptions-item label="创建时间">
            {{ formatDate(currentRoute.created_at) }}
          </el-descriptions-item>
        </el-descriptions>
      </div>

      <!-- 编辑/新增模式 -->
      <div v-else class="form-content">
        <el-form
          ref="routeForm"
          :model="form"
          :rules="formRules"
          label-width="100px"
        >
          <el-card class="form-section" shadow="never">
            <template #header>
              <span class="form-section-title">基本配置</span>
            </template>
            <el-row :gutter="20">
              <el-col :span="12">
                <el-form-item label="路由名称" prop="linkName">
                  <el-input
                    v-model="form.linkName"
                    placeholder="请输入路由名称（30字符内）"
                    maxlength="30"
                    show-word-limit
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="协议" prop="protocol">
                  <el-input
                    v-model="form.protocol"
                    placeholder="例如: litmatch（域名路径包含协议时可留空）"
                    :disabled="domainHasProtocol"
                  >
                    <template #append>://</template>
                  </el-input>
                  <div v-if="domainHasProtocol" class="form-hint">
                    检测到域名路径已包含协议，此字段已禁用
                  </div>
                </el-form-item>
              </el-col>
            </el-row>

            <el-form-item label="路径" prop="domain">
              <el-input
                v-model="form.domain"
                placeholder="例如: litatom.com/gift/detail 或 litatom://litatom.com/gift/detail"
                type="textarea"
                :rows="2"
              />
              <div class="form-hint">
                支持直接输入完整URL（包含协议）或仅输入域名路径
              </div>
            </el-form-item>
          </el-card>

          <el-card class="form-section" shadow="never">
            <template #header>
              <div class="form-section-header">
                <span class="form-section-title">参数配置</span>
                <el-button @click="addParam" size="small" type="primary" plain>
                  <SvgIcon name="add" size="14px" />
                  <span style="margin-left: 4px">添加参数</span>
                </el-button>
              </div>
            </template>
            <div class="params-container">
              <div
                v-for="(param, index) in form.params"
                :key="index"
                class="param-item"
              >
                <el-row :gutter="10" align="middle">
                  <el-col :span="10">
                    <el-input
                      v-model="param.key"
                      placeholder="参数名(例如: id)"
                      size="small"
                    />
                  </el-col>
                  <el-col :span="1" class="param-equal">=</el-col>
                  <el-col :span="10">
                    <el-input
                      v-model="param.value"
                      placeholder="参数值"
                      size="small"
                    />
                  </el-col>
                  <el-col :span="3">
                    <el-button
                      @click="removeParam(index)"
                      size="small"
                      type="danger"
                      plain
                      :disabled="form.params.length === 1"
                    >
                      <SvgIcon name="delete" size="14px" />
                    </el-button>
                  </el-col>
                </el-row>
              </div>
            </div>
          </el-card>

          <el-card class="form-section" shadow="never">
            <template #header>
              <span class="form-section-title">路由预览</span>
            </template>
            <div class="preview-container">
              <el-input
                :value="generatedLink || '请填写协议和域名路径'"
                readonly
                type="textarea"
                :rows="3"
                class="preview-input"
              >
                <template #append>
                  <el-tooltip content="复制预览链接" placement="top">
                    <el-button
                      v-if="generatedLink"
                      @click="copyToClipboard(generatedLink)"
                      type="primary"
                    >
                      <SvgIcon name="copy" size="14px" />
                    </el-button>
                  </el-tooltip>
                </template>
              </el-input>
            </div>
          </el-card>
        </el-form>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="closeModal">取消</el-button>
          <el-button
            v-if="modalMode === 'view'"
            @click="testRoute(currentRoute.url)"
            type="success"
          >
            测试路由
          </el-button>
          <el-button
            v-else
            @click="saveRoute"
            type="primary"
            :loading="submitting"
          >
            {{ submitting ? '保存中...' : '保存' }}
          </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 删除确认弹窗 -->
    <el-dialog
      v-model="showDeleteModal"
      title="确认删除"
      width="400px"
      :close-on-click-modal="false"
    >
      <div class="delete-content">
        <el-alert
          title="确定要删除此路由吗？"
          type="warning"
          :closable="false"
          show-icon
        />
        <div class="delete-info">
          <p>
            <strong>路由名称:</strong>
            {{ deleteRoute?.link_name || '未命名路由' }}
          </p>
          <p>
            <strong>路由地址:</strong>
            {{ deleteRoute?.url }}
          </p>
          <p class="delete-warning">⚠️ 此操作不可恢复！</p>
        </div>
      </div>

      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancelDelete">取消</el-button>
          <el-button @click="executeDelete" type="danger" :loading="deleting">
            {{ deleting ? '删除中...' : '确认删除' }}
          </el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'
import SvgIcon from '@/views/components/SvgIcon.vue'
import request from '@/utils/request'

export default {
  name: 'RouteManageV2',
  components: {
    SvgIcon,
  },
  data() {
    return {
      routes: [],
      searchQuery: '',
      loading: false,
      error: null,

      // 分页
      currentPage: 1,
      pageSize: 10,

      // 弹窗相关
      showModal: false,
      modalMode: 'view', // 'view', 'add', 'edit'
      currentRoute: {},
      submitting: false,

      // 删除确认
      showDeleteModal: false,
      deleteRoute: null,
      deleting: false,

      // 表单数据
      form: {
        linkName: '',
        protocol: '',
        domain: '',
        params: [{ key: '', value: '' }],
      },

      // 表单验证规则
      formRules: {
        linkName: [
          { required: true, message: '请输入路由名称', trigger: 'blur' },
          { max: 30, message: '路由名称长度不能超过30个字符', trigger: 'blur' },
        ],
        protocol: [
          {
            validator: (rule, value, callback) => {
              if (!this.domainHasProtocol && (!value || value.trim() === '')) {
                callback(new Error('协议不能为空'))
              } else {
                callback()
              }
            },
            trigger: 'blur',
          },
        ],
        domain: [
          { required: true, message: '请输入域名路径', trigger: 'blur' },
          { min: 3, message: '域名路径长度至少3个字符', trigger: 'blur' },
        ],
      },
    }
  },

  computed: {
    filteredRoutes() {
      if (!this.searchQuery.trim()) {
        return this.routes
      }

      const query = this.searchQuery.toLowerCase()
      return this.routes.filter((route) => {
        const name = (route.link_name || '').toLowerCase()
        const url = (route.url || '').toLowerCase()
        return name.includes(query) || url.includes(query)
      })
    },

    totalPages() {
      return Math.ceil(this.filteredRoutes.length / this.pageSize)
    },

    paginatedRoutes() {
      const start = (this.currentPage - 1) * this.pageSize
      const end = start + this.pageSize
      return this.filteredRoutes.slice(start, end)
    },

    modalTitle() {
      const titles = {
        view: '查看路由',
        add: '新增路由',
        edit: '编辑路由',
      }
      return titles[this.modalMode] || '路由操作'
    },

    generatedLink() {
      if (!this.form.domain.trim()) {
        return ''
      }

      const protocolPattern = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//
      const hasProtocol = protocolPattern.test(this.form.domain.trim())

      let link
      if (hasProtocol) {
        link = this.form.domain.trim()
      } else {
        if (!this.form.protocol.trim()) {
          return ''
        }
        link = `${this.form.protocol.trim()}://${this.form.domain.trim()}`
      }

      const queryParams = this.form.params
        .filter((param) => param.key.trim() !== '')
        .map((param) => `${param.key.trim()}=${param.value}`)
        .join('&')

      if (queryParams) {
        const separator = link.includes('?') ? '&' : '?'
        link += `${separator}${queryParams}`
      }

      return link
    },

    domainHasProtocol() {
      if (!this.form.domain.trim()) {
        return false
      }
      const protocolPattern = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//
      return protocolPattern.test(this.form.domain.trim())
    },
  },

  watch: {
    searchQuery() {
      this.currentPage = 1
    },

    'form.domain': {
      handler(newValue) {
        const protocolPattern = /^[a-zA-Z][a-zA-Z\d+\-.]*:\/\//
        if (protocolPattern.test(newValue.trim())) {
          this.form.protocol = ''
        }
      },
      immediate: true,
    },
  },

  mounted() {
    this.fetchRoutes()
  },

  methods: {
    async fetchRoutes() {
      try {
        this.loading = true
        this.error = null
        const response = await request.get('/devices/test')

        // 调试信息：打印完整响应（注意：响应拦截器已经返回了response.data）
        console.log('路由列表API响应:', response)

        // 修正：由于响应拦截器返回response.data，所以response就是原始的data部分
        // 适配新的响应格式：response.data.links
        if (
          response &&
          response.success &&
          response.data &&
          Array.isArray(response.data.links)
        ) {
          console.log('使用新格式，路由数据:', response.data.links)
          this.routes = response.data.links
        } else if (response && Array.isArray(response)) {
          // 兼容旧格式：直接是数组
          console.log('使用旧格式，路由数据:', response)
          this.routes = response
        } else if (response && response.data && Array.isArray(response.data)) {
          // 可能的格式：response.data 直接是数组
          console.log('使用备用格式，路由数据:', response.data)
          this.routes = response.data
        } else {
          console.log('未识别的响应格式，设置为空数组')
          console.log('响应结构:', response)
          this.routes = []
        }

        console.log('最终路由数据:', this.routes)
      } catch (error) {
        console.error('获取路由列表失败:', error)
        this.error = '获取路由列表失败，请稍后重试'
        this.routes = []
      } finally {
        this.loading = false
      }
    },

    refreshRoutes() {
      this.fetchRoutes()
    },

    viewRoute(route) {
      this.currentRoute = { ...route }
      this.modalMode = 'view'
      this.showModal = true
    },

    openAddModal() {
      this.resetForm()
      this.modalMode = 'add'
      this.showModal = true
    },

    editRoute(route) {
      this.currentRoute = { ...route }
      this.parseRouteToForm(route)
      this.modalMode = 'edit'
      this.showModal = true
    },

    parseRouteToForm(route) {
      this.form.linkName = route.link_name || ''

      // 解析URL到表单字段
      const url = route.url || ''
      try {
        const urlObj = new URL(url)

        // 提取协议
        this.form.protocol = urlObj.protocol.replace(':', '')

        // 提取域名和路径
        this.form.domain = urlObj.host + urlObj.pathname

        // 提取参数
        this.form.params = []
        urlObj.searchParams.forEach((value, key) => {
          this.form.params.push({ key, value })
        })

        if (this.form.params.length === 0) {
          this.form.params.push({ key: '', value: '' })
        }
      } catch (error) {
        // URL解析失败，直接使用原始URL
        this.form.protocol = ''
        this.form.domain = url
        this.form.params = [{ key: '', value: '' }]
      }
    },

    closeModal() {
      this.showModal = false
      this.currentRoute = {}
      this.resetForm()
    },

    resetForm() {
      this.form = {
        linkName: '',
        protocol: '',
        domain: '',
        params: [{ key: '', value: '' }],
      }
    },

    addParam() {
      this.form.params.push({ key: '', value: '' })
    },

    removeParam(index) {
      if (this.form.params.length > 1) {
        this.form.params.splice(index, 1)
      }
    },

    async saveRoute() {
      try {
        await this.$refs.routeForm.validate()

        this.submitting = true

        const data = {
          link: this.generatedLink,
          link_name: this.form.linkName,
        }

        let response
        if (this.modalMode === 'add') {
          response = await request.post('/devices/test_send', data)
        } else if (this.modalMode === 'edit') {
          response = await request.put(
            `/devices/test/${this.currentRoute.id}`,
            data,
          )
        }

        // 检查响应格式（注意：响应拦截器已经返回了response.data）
        if (response && response.success) {
          ElMessage.success(
            response.message ||
              (this.modalMode === 'add' ? '路由添加成功' : '路由更新成功'),
          )
        } else {
          ElMessage.success(
            this.modalMode === 'add' ? '路由添加成功' : '路由更新成功',
          )
        }

        this.closeModal()
        this.fetchRoutes()
      } catch (error) {
        console.error('保存路由失败:', error)

        // 尝试从错误响应中获取错误信息（注意：响应拦截器返回data）
        let errorMessage = '保存路由失败，请稍后重试'
        if (error && error.message) {
          errorMessage = error.message
        } else if (typeof error === 'string') {
          errorMessage = error
        }

        ElMessage.error(errorMessage)
      } finally {
        this.submitting = false
      }
    },

    confirmDelete(route) {
      this.deleteRoute = route
      this.showDeleteModal = true
    },

    cancelDelete() {
      this.showDeleteModal = false
      this.deleteRoute = null
    },

    async executeDelete() {
      if (!this.deleteRoute) return

      try {
        this.deleting = true
        const response = await request.delete(
          `/devices/test/${this.deleteRoute.id}`,
        )

        // 检查响应格式（注意：响应拦截器已经返回了response.data）
        if (response && response.success) {
          ElMessage.success(response.message || '路由删除成功')
        } else {
          ElMessage.success('路由删除成功')
        }

        this.cancelDelete()
        this.fetchRoutes()
      } catch (error) {
        console.error('删除路由失败:', error)

        // 尝试从错误响应中获取错误信息（注意：响应拦截器返回data）
        let errorMessage = '删除路由失败，请稍后重试'
        if (error && error.message) {
          errorMessage = error.message
        } else if (typeof error === 'string') {
          errorMessage = error
        }

        ElMessage.error(errorMessage)
      } finally {
        this.deleting = false
      }
    },

    async copyToClipboard(text) {
      try {
        await navigator.clipboard.writeText(text)
        ElMessage.success('复制成功')
      } catch (error) {
        console.error('复制失败:', error)
        ElMessage.error('复制失败，请手动复制')
      }
    },

    testRoute(url) {
      if (url) {
        window.open(url, '_blank')
      }
    },

    formatDate(dateString) {
      if (!dateString) return '-'
      const date = new Date(dateString)
      return date.toLocaleString('zh-CN')
    },
  },
}
</script>

<style scoped>
/* 基础容器样式 */
.route-manage-container {
  padding: 20px;
  /* background: white; */
  min-height: calc(100vh - 74px);
  max-width: 100%;
  margin: 0;
  width: 100%;
}

/* 页面头部 */
.page-header {
  margin-bottom: 8px;
}

.page-header h3 {
  margin: 0;
  color: #303133;
  font-size: 22px;
  font-weight: 600;
}

/* 工具栏样式 */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 12px;
}

.left-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.left-section h3 {
  margin: 0;
  color: #303133;
  font-size: 16px;
  font-weight: 600;
}

.route-summary {
  padding: 2px 8px;
  /* background: #f0f7ff; */
  border-radius: 4px;
  border: 1px solid var(--el-border-color);
}

.summary-text {
  color: #409eff;
  font-size: 12px;
  font-weight: 500;
}

.right-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.search-input {
  width: 300px;
}

/* 路由内容样式 */
.routes-content {
  /* background: white; */
  border-radius: 6px;
  border: 1px solid var(--el-border-color);
  overflow: hidden;
  margin-bottom: 8px;
  height: calc(100vh - 210px);
  position: relative;
}

/* 表格容器居中 */
.routes-content .el-table {
  margin: 0 auto;
}

/* 错误信息样式 */
.error-message {
  margin: 12px;
}

/* 空状态样式 */
.empty-message {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* background: white; */
}

.route-table {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.route-table :deep(.el-table) {
  flex: 1;
  border-radius: 6px;
}

.route-table :deep(.el-table__body-wrapper) {
  overflow-y: auto;
  flex: 1;
}

.route-name-cell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.route-name {
  font-weight: 500;
  color: #303133;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.route-url-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.route-url {
  flex: 1;
  color: #409eff;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.route-url:hover {
  text-decoration: underline;
}

.copy-btn {
  padding: 4px;
  min-width: auto;
  color: #409eff;
}

.copy-btn:hover {
  color: #66b1ff;
}

.route-time {
  color: #909399;
  font-size: 13px;
}

.action-buttons {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.pagination-container {
  display: flex;
  justify-content: flex-start;
  margin: 4px 0;
  padding: 12px 16px;
  border-top: 1px solid var(--el-border-color);
  /* background-color: #ffffff; */
}

/* 弹窗样式 */
.view-content {
  padding: 10px 0;
}

.route-url-display {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-content {
  padding: 10px 0;
}

.form-section {
  margin-bottom: 20px;
}

.form-section:last-child {
  margin-bottom: 0;
}

.form-section-title {
  font-size: 14px;
  font-weight: 600;
  color: #303133;
}

.form-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.form-hint {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
}

.params-container {
  width: 100%;
}

.param-item {
  margin-bottom: 12px;
}

.param-item:last-child {
  margin-bottom: 0;
}

.param-equal {
  text-align: center;
  color: #909399;
  font-weight: 500;
}

.preview-container {
  width: 100%;
}

.preview-input {
  width: 100%;
}

.preview-input :deep(.el-textarea__inner) {
  /* background-color: #f5f7fa; */
  border-color: var(--el-border-color);
  color: #409eff;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* 删除确认弹窗 */
.delete-content {
  padding: 10px 0;
}

.delete-info {
  margin-top: 16px;
  padding: 12px;
  /* background-color: #fef0f0; */
  border-radius: 4px;
  border: 1px solid var(--el-border-color);
}

.delete-info p {
  margin: 8px 0;
  font-size: 14px;
  color: #606266;
}

.delete-info p:first-child {
  margin-top: 0;
}

.delete-info p:last-child {
  margin-bottom: 0;
}

.delete-warning {
  color: #f56c6c !important;
  font-weight: 500;
}

/* Element Plus Card 内边距定制 */
.form-section :deep(.el-card__body) {
  padding: 16px;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .route-manage-container {
    padding: 8px;
  }

  .page-header h3 {
    font-size: 20px;
  }

  .toolbar {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .left-section,
  .right-section {
    flex-direction: column;
    gap: 12px;
    width: 100%;
  }

  .search-input {
    width: 100%;
  }

  .routes-content {
    height: calc(100vh - 210px);
  }

  .form-section :deep(.el-card__body) {
    padding: 12px;
  }
}

@media (max-width: 992px) {
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .right-section {
    width: 100%;
    justify-content: flex-start;
  }

  .routes-content {
    height: calc(100vh - 230px);
  }
}
</style> 